
JavaScript have many string methods for string modification or we can get many properties of the string using this string method. JavaScript string methods are very useful for programmer to get the many important property or specific value from the any string. Now given bellow some string function name:
• indexOf
• lastIndexOf
• length
• search
• slice
• replace
• toLowerCase
• toUpperCase
Now given bellow the string method code and explain the code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var name = "Farhan Sakib Jesy!";
//get the index
console.log(name.indexOf("Sakib"));
console.log(name.lastIndexOf("Sakib"));
//get the length
console.log(name.length);
//returns the position of the first occurrence of a specified text in a string
console.log(name.search("Sakib"));
//get specific words from string
console.log(name.slice(0, 13));
//replace specific word
console.log(name.replace("Jesy", "...."))
//get Lower Case
console.log(name.toLowerCase())
//get Upper Case
console.log(name.toUpperCase())
</script>
</body>
</html>
In this code we have a variable name as “name”. This name variable contains the my “Farhan Sakib Jesy” string. This string modifies, replace, Upper case or Lower case etc perform by the string functions. We can easily write our code using this function. If we use this function our code will be more read abele and clean for the programmer.